package thread;

public class ThreadDemo9_4 {

	public static void main(String[] args) {
		
		Ticket2 ticket = new Ticket2();
		Ticket3 ticket3 = new Ticket3();
		
		Thread t1 = new Thread(ticket, "窗口1");
		Thread t2 = new Thread(ticket3, "守护线程");
		Thread t3 = new Thread(ticket, "窗口3");
		
		//t1.setPriority(Thread.NORM_PRIORITY + 4);
		//t2.setDaemon(true);
		
		t1.start();
		//t2.start();
		//t3.start();
		/*try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		t1.interrupt();
	}

}

class Ticket2 implements Runnable {
	private int ticket = 20;

	
	@Override
	public void run() {
		while( this.ticket > 0 ){
			ticket--;
			/*try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}*/
			System.out.println(Thread.currentThread().getName()+ "卖掉一张票,还有余票:" + ticket);
		}
	}
	
}

class Ticket3 implements Runnable {

	@Override
	public void run() {
		// TODO Auto-generated method stub
		while( true ){
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println("一句话新闻");
		}
	}
	
}
